package br.inf.ufrgs.br.usixml4cdc.rendering.javadesktop.utils;

import java.awt.Insets;
import java.text.NumberFormat;
import java.text.ParseException;

import br.inf.ufrgs.usixml4cdc.exceptions.ParsingErrorException;

public class InformationParser {
	
	public Insets parseInsets(String insets)
		throws ParsingErrorException{
		
		int[] insetsArray = new int[4];
		insetsArray[0] = 2;
                insetsArray[1] = 2;
                insetsArray[2] = 2;
                insetsArray[3] = 2;
		
//                Scanner scan = new Scanner(insets).useDelimiter(",");
//		try{
//			insetsArray[0] = NumberFormat.getIntegerInstance().parse(scan.next()).intValue();
//			insetsArray[1] = NumberFormat.getIntegerInstance().parse(scan.next()).intValue();
//			insetsArray[2] = NumberFormat.getIntegerInstance().parse(scan.next()).intValue();
//			insetsArray[3] = NumberFormat.getIntegerInstance().parse(scan.next()).intValue();
//		}catch (ParseException e){
//			throw new ParsingErrorException("Invalid insets argument");
//		}
		
		Insets newInsets = new Insets(insetsArray[0],insetsArray[1],insetsArray[2],insetsArray[3]);
		
		return newInsets;
	}
	
	public int parseFlowLayoutAlignment(String alignment)
		throws ParsingErrorException{
	
		if (alignment.equals("left")){
			return java.awt.FlowLayout.LEFT;
		} else if (alignment.equals("right")){
			return java.awt.FlowLayout.RIGHT;
		} else if (alignment.equals("center")){
			return java.awt.FlowLayout.CENTER;
		} else {
			throw new ParsingErrorException("Invalid alignment type");
		}
	}

}
